/*
   @Copyright:LibreOJ
   @Author:   tjyemail
   @Problem:  https://loj.ac/problem/101
   @Language: C++
   @Datetime: 20-08-14 14:07
   */
// Dinic using Linked Forward Star, time O(E*V^2) 31ms

#include <bits/stdc++.h>
using namespace std;

#define VERTEX 102
#define EDGE 5002
// linked forward star
struct Edge {
	int v, next;
	long long cap;
	Edge(int v=0, long long cap=0, int next=-1):v(v), cap(cap), next(next){}
} edges[EDGE*2];
int heads[VERTEX];
int ie = 0;
inline void add(int u, int v, long long cap) {
	edges[ie] = Edge(v, cap, heads[u]);
	heads[u] = ie++;
	// 1) reverse edge position must be ie+1
	// 2) edges position must from 0 => heads must initialize as -1
	// so, the reverse edge position is ie^1.
	edges[ie] = Edge(u, 0, heads[v]); // reverse edge
	heads[v] = ie++;
}
int deeps[VERTEX], curs[VERTEX]; // current available edge position

bool bfs(int v, int s, int t) {
	memset(deeps, 0, sizeof(int)*(v+1));
	deeps[s] = 1;
	queue<int> vs;
	for(vs.push(s); !vs.empty(); vs.pop()) {
		s = vs.front();
		for(int k=heads[s]; k!=-1; k=edges[k].next) {
			if (deeps[edges[k].v] || edges[k].cap<1) continue;
			deeps[edges[k].v] = deeps[s] + 1;
			vs.push(edges[k].v);
		}
	}
	return deeps[t]; // check if it has path s->t
}

long long dfs(int s, int t, long long cap=INT_MAX) {
	if (cap==0 || s==t) return cap;
	long long flow = 0, cur = 0;
	for(int k=curs[s]; k!=-1 && flow!=cap; k=edges[k].next) {
		curs[s] = k; // record current available edge position
		if (deeps[edges[k].v]!=deeps[s]+1 || edges[k].cap<1) continue;
		cur = dfs(edges[k].v, t, min(cap-flow, edges[k].cap));
		edges[k].cap -= cur;
		edges[k^1].cap += cur; // reverse edge
		flow += cur;
	}
	return flow;
}

void dinic(int v, int s, int t) {
	long long flow = 0;
	while(bfs(v, s, t)) {
		memcpy(curs, heads, sizeof(int)*(v+1));
		flow += dfs(s, t);
	}
	printf("%lld\n", flow);
}

int main()
{
	int v, e, s, t, a, b, c; // vertex edge, source -> target
	scanf("%d %d %d %d", &v, &e, &s, &t);
	memset(heads, -1, sizeof(heads));
	for(int i=0; i++<e; ) {
		scanf("%d %d %d", &a, &b, &c); // a->b, capacity
		add(a, b, c);
	}
	dinic(v, s, t);
	return 0;
}
